import {timerUtil} from '../../../utils'

window.EcExtension?.ready?.(() => {
    if (window.ecodeSDK && location.hash.startsWith('#/main/workflow/req')) {
        window.EcExtension.Menus.register('模板设置', () => {
            const win: any = window.open(`/wui/engine.html#/workflowengine/path/pathSet/pathDetail/flowSet/nodeInfo?workflowId=${window.WfForm.getBaseInfo().workflowid}`)
            timerUtil.setIntervalPromise((resolve) => {
                if (win.workflowNodeSetUtil) {
                    win.workflowNodeSetUtil.onShowForm(window.WfForm.getBaseInfo().nodeid, window.WfForm.getBaseInfo().workflowid)
                    resolve()
                }
            }, 100, 3 * 60 * 1000).then(() => {
                return timerUtil.setIntervalPromise((resolve) => {
                    const a = win.document.querySelector('a[ecid="_Route@ysl6sy_FormContentModal@95a6zn_SetFormContent@crrg8j_ShowTemplate@e5ooj0_WeaSwitch@mcsiac@showTemplate_BrowserItem@kcmxcj_WeaBrowser@79lp8q_WrappedComponent@i9q2c5_Component@iiw91q_Associative@zt8qgk_a@ml5n00@0"]')
                    if (a) {
                        a.click()
                        resolve()
                    }
                }, 100, 3 * 60 * 1000)
            }).catch(err => {
                alert('err:' + err.message)
            })
        })
    }
})